package com.xhwl.logistics.validate.blacklist;

import com.xhwl.common.exception.BusinessException;
import com.xhwl.logistics.bo.VehicleParkingLotSecondBO;
import com.xhwl.logistics.dto.manipulate.VehicleBlacklistCreateDTO;
import com.xhwl.logistics.entity.VehicleBlacklist;
import com.xhwl.logistics.service.impl.VehicleBlacklistServiceImpl;
import com.xhwl.logistics.service.impl.VehicleParkingLotServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

public class CreateBlacklistConstraintValidator implements ConstraintValidator<CreateBlacklistConstraint, VehicleBlacklistCreateDTO> {

    @Autowired
    private VehicleParkingLotServiceImpl vehicleParkingLotService;

    @Autowired
    private VehicleBlacklistServiceImpl vehicleBlacklistService;

    @Override
    public boolean isValid(VehicleBlacklistCreateDTO vehicleBlacklistCreateDTO, ConstraintValidatorContext context) {
        Integer projectId = vehicleBlacklistCreateDTO.getProjectId();
        String parkingLotName = vehicleBlacklistCreateDTO.getParkingLotName();

        VehicleParkingLotSecondBO vehicleParkingLotSecondBO = vehicleParkingLotService.queryParkingLot(projectId, parkingLotName);

        List<VehicleBlacklist> vehicleBlacklistList = null;
        /*vehicleBlacklistService.list(new LambdaQueryWrapper<>(VehicleBlacklist.class).eq(VehicleBlacklist::getProjectId, projectId)
                .eq(VehicleBlacklist::getParkingLotName, vehicleParkingLotSecondBO.getParkingLotName())
                .eq(VehicleBlacklist::getPlateNumber, vehicleBlacklistCreateDTO.getPlateNumber()));*/
        if (!vehicleBlacklistList.isEmpty()) {
            throw new BusinessException("在该项目下的车场中，黑名单已经存在了该车牌号码");
        }

        return true;
    }

}
